import pandas as pd
from docx import Document
from datetime import datetime

# 读取数据
df = pd.read_excel('sales_data.xlsx')

# 生成报表
report = Document()
report.add_heading('销售报表', 0)
report.add_paragraph(f'生成时间：{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}')

# 添加表格
table = report.add_table(rows=1, cols=len(df.columns))
hdr_cells = table.rows[0].cells
for i, col in enumerate(df.columns):
    hdr_cells[i].text = col

# 添加数据行
for _, row in df.iterrows():
    row_cells = table.add_row().cells
    for i, value in enumerate(row):
        row_cells[i].text = str(value)

# 保存报表
report.save('sales_report.docx')